<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <father></father>
    </div>
    <script src="./node_modules/vue/dist/vue.js"></script>
    <script>
        Vue.component('father',{
            template:`
                <div>
                    <son1 ref="aaa"></son1>
                    <son2 @my-event="add"></son2>    
                </div>
            `,
            methods:{
                add(item){
                    this.$refs.aaa.list.push(item)
                }
            },
            components:{
                son1:{
                    template:`
                        <ul>
                            <li v-for="(item,index) in list" :key="index">{{item}}</li>    
                        </ul>
                    `,
                    data(){
                        return {
                            list:[2,3,4]
                        }
                    }
                },
                son2:{
                    template:`
                        <button @click="fn">按钮</button>
                    `,
                    methods: {
                        fn(){
                            this.$emit('my-event',5)
                        }
                    },
                }
            }
        })
        var vm = new Vue({
            el:'#app',
            data:{
                
            },
            methods:{
                
            }
        })
    </script>
</body>
</html>
